package oec_service

import (
	"beta/models"
	"beta/pkg/e"
	"beta/pkg/logger"
	"github.com/jinzhu/gorm"
	"time"
)

type OecService struct {
	Hosts map[string]*models.AppEnv
	TraceId string
}

var (
	appName = "oec"
)

type OecConsumePtsOriginalRecord struct {
	BusinessId string
	CustomerId string
	CustomerName string
	CompanyId string
	CompanyName string
	DeptId string
	DeptName string
	EmployeeId string
	LicenseType string
	LicenseNumber string
	ServiceCode string
	ServiceType string
	ConsumeTime string
	ActionType string
	SubdivisionActionType string
	Status string
}

func (oec OecService) AddConsumeData(customerId string) error {
	DbUrl := oec.Hosts[appName].AppMysql + "?charset=utf8&parseTime=True&loc=Local"
	db, connErr := gorm.Open("mysql", DbUrl)
	if  connErr != nil {
		logger.ZapLogger.Infow("【添加消耗记录】", "连接地址", DbUrl, "连接错误信息", connErr)
		return connErr
	}

	consumeTime := time.Now().AddDate(0, -1, 0).Format(e.TimeFormat)

	data := OecConsumePtsOriginalRecord{
		BusinessId:            "8b59c96af69f4d0b84cc35d60414dde9",
		CustomerId:            customerId,
		CustomerName:          "beta-autotest中介",
		CompanyId:             "835999252606",
		CompanyName:           "beta-autotest公司",
		DeptId:                "1",
		DeptName:              "测试部门",
		EmployeeId:            "96031577",
		LicenseType:           "201",
		LicenseNumber:         "6698692802bc4f25afb7a0f4b936addb" + customerId,
		ServiceCode:           "PTS_JG_SWXD",
		ServiceType:           "01",
		ConsumeTime:           consumeTime,
		ActionType:            "IIT_CALCULATE",
		SubdivisionActionType: "normalSalarySpecIncome",
		Status:                "untreated",
	}

	defer db.Close()

	if err := db.Table("oec_consume_pts_original_record").Create(&data).Error; err != nil {
		logger.ZapLogger.Infow("【添加消耗记录】", "错误信息", err)
		return err
	}

	return nil

}